package com.googlecode.messwertepi.module;

import com.google.inject.Provider;
import com.googlecode.messwertepi.configuration.Configuration;
import com.googlecode.messwertepi.configuration.XMLConfiguration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by eike on 25.06.14.
 */
public class ConfigurationProvider implements Provider<Configuration>
{
    final private static Logger LOG = LoggerFactory.getLogger(ConfigurationProvider.class);

    @Override
    public Configuration get()
    {
        try {
            HierarchicalConfiguration xmlConfig = new org.apache.commons.configuration.XMLConfiguration("configuration.xml");
            return new XMLConfiguration(xmlConfig);
        } catch (ConfigurationException ce) {
            throw new RuntimeException("Failed to load the configuration.xml file. Please make sure it is in the classpath.", ce);
        }
    }
}
